package com.lzclass.servlet.whyservlet;

import com.alibaba.fastjson.JSON;

import com.lzclass.service.whyservice.ArcitleService;
import com.lzclass.util.ServiceUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
////    通过类型搜索相关帖子
////    点击分类查询相关帖子
//需要参数：typename
//返回参数:List<Article,List<Article_Type>, List<BackMessage>>
@WebServlet("/cha")
public class ArcitleByTypenameServlet extends HttpServlet {
    private ArcitleService arcitleService = (ArcitleService) ServiceUtil.getService("arcitleServiceImpl");
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String typename = req.getParameter("java");


        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write(JSON.toJSONString(arcitleService.allfindArcitleByType(typename)));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
